'use strict';

function median_to_letter(collection) {

  let madian;
  if(collection.length%2 == 0){
    madian = parseInt( ( collection[collection.length/2 - 1] + collection[collection.length/2] ) / 2 )
    if( ( collection[collection.length/2 - 1] + collection[collection.length/2] ) % 2!=0 ){
      madian+=1;
    }
  }
  else{
    madian = collection[collection.length];
  }
  return numToChar(madian);
}

function numToChar(num) {
  let remainder = num%26;
  let quotient = parseInt(num/26);

  if(quotient === 0){
    return String.fromCharCode(remainder+96)
  }else if(quotient ===1&&remainder===0){
    return 'z';
  }else if(quotient > 1&&remainder===0){
    return numToChar(quotient-1) + 'z';
  }else {
    return numToChar(quotient) + String.fromCharCode(remainder+96);
  }
}

module.exports = median_to_letter;
